<?php
Yii::app()->clientScript->registerCoreScript('jquery');?>



<div class="search-wrapper">
    <form method="get" action="<?php HSUrl::searchUrl() ?>">
        <input type="text" name="keywords" style="width: 300px"/>
        <input type="submit" value="Search">
    </form>
</div>
<style>
    a {
        text-decoration: none;
    }

    .pagination ul {
        list-style: none;
    }

    .pagination ul li {
        display: inline;
    }

    .pagination ul li a {
        padding: 10px;
    }

    .pagination ul li.active {
        text-decoration: underline;
    }
</style>

<div class="content-wrapper">

    <?php if (count($model) == 0 && isset($_GET['keywords'])) echo "Không tìm thấy sản phẩm";
    elseif (count($model) > 0 && isset($_GET['keywords'])) {
        ?>
        <div id="divPrint">
            <img alt="print" src="<?php echo HSUrl::home() . '/images/printer.png' ?>" title="Print">
            <label id="print">Print</label>
        </div>
        <?php foreach ($model as $item) {
            ?>

            <div style="border: 1px solid #000000;padding: 10px">
                <div
                    style="float: left;min-width: 150px;min-height: 150px;max-width: 150px;margin-right: 15px;width: 30%;text-align: center">
                    <img src="<?php echo $item->picture ?>" alt="" style="max-width: 150px"/>
                </div>
                <div style="float: left;width: 70%">
                    <h2>
                        <?php echo $item->name ?>
                    </h2>
                    <div><?php echo HSCommon::handlePrice($item->price) ?></div>
                    <div>
                        <a href="<?php echo $item->url ?>">Link chi tiết</a>
                    </div>
                </div>
                <div style="clear: both"></div>
            </div>

        <?php
        }?>
        <div class="pagination" style="text-align: center">
            <?php
            $this->widget('CLinkPager', array(
                'currentPage' => $pages->getCurrentPage(),
                'itemCount' => $item_count,
                'pageSize' => $page_size,
                'maxButtonCount' => 5,
                'header' => '',
                'firstPageLabel' => '<<',
                'lastPageLabel' => '>>',
                'nextPageLabel' => 'Sau',
                'prevPageLabel' => 'Trước',
                'selectedPageCssClass' => 'active',
                'hiddenPageCssClass' => 'disabled',
                'htmlOptions' => array(
                    "class" => "pagination"
                ),
            ));
            ?>
        </div>
    <?php
    }
    ?>

</div>

<script type="text/javascript">
    $(document).ready(function () {
        $('#print').click(function () {
            var $search_wrapper = $(".search-wrapper");
            var $print = $("#divPrint");
            var $pagination = $(".pagination");

            $search_wrapper.attr('style', 'display:none');
            $print.attr('style', 'display:none');
            $pagination.attr('style', 'display:none');

            window.print();
            $search_wrapper.attr('style', 'display:block');
            $print.attr('style', 'display:block');
            $pagination.attr('style', 'display:block');
            return false;
        });
    });
</script>